<script type="text/javascript" src="javascript/ajax/prototype.js"></script>
<script type="text/javascript" src="modules/InnoForum/pnjavascript/NumberFormat154.js"></script>
  <script type="text/javascript">

        function validateFinance(){
           
          //Check company_name
          var company_name = document.getElementById("company_name");
          if (trimString(company_name.value) == '') {
            alert("กรุณากรอกชื่อบริษัท");
            document.getElementById('error-company_name').innerHTML = "<FONT COLOR='#FF0000'>*</FONT>";
            company_name.style.borderStyle = "solid";
            company_name.style.borderColor = "#FF0000";
            company_name.style.borderWidth = "1px";
            company_name.focus();
            return false;
          }else{
            company_name.style.borderStyle = "solid";
            company_name.style.borderColor = "#00CC00";
            company_name.style.borderWidth = "1px";
            document.getElementById('error-company_name').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
          }
          
          //Check telephone
          var finance_telephone = document.getElementById("finance_telephone");
          if (trimString(finance_telephone.value) == '') {
            alert("กรุณากรอกเบอร์โทรศัพท์");
            document.getElementById('error-finance_telephone').innerHTML = "<FONT COLOR='#FF0000'>*</FONT>";
            finance_telephone.style.borderStyle = "solid";
            finance_telephone.style.borderColor = "#FF0000";
            finance_telephone.style.borderWidth = "1px";
            finance_telephone.focus();
            return false;
          }else{
            finance_telephone.style.borderStyle = "solid";
            finance_telephone.style.borderColor = "#00CC00";
            finance_telephone.style.borderWidth = "1px";
            document.getElementById('error-finance_telephone').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
          }

          //Check email
          var finance_email  = document.getElementById("finance_email");
          //alert(email.value);
          var finance_email1 = new String(finance_email.value);
          //alert(finance_email1);
          finance_email1 = trimString(finance_email1);
          if (trimString(finance_email.value) == '') {
            alert("กรุณากรอกอีเมล์");
            finance_email.style.borderStyle = "solid";
            finance_email.style.borderColor = "#FF0000";
            finance_email.style.borderWidth = "1px";
            finance_email.focus();
            return false;
          }
          if (!isEmail(finance_email1)) {
            alert("กรุณากรอกอีเมล์ให้ถูกต้อง");
            finance_email.style.borderStyle = "solid";
            finance_email.style.borderColor = "#FF0000";
            finance_email.style.borderWidth = "1px";
            finance_email.focus();
            return false;
          }else{
              finance_email.style.borderStyle = "solid";
              finance_email.style.borderColor = "#00CC00";
              finance_email.style.borderWidth = "1px";
              document.getElementById('error-finance_email').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
          }
           
          //Check balance
          var balance = document.getElementById("balance");
          if (trimString(balance.value) == '') {
            alert("กรุณากรอกยอดจัดไฟแนนซ์");
            document.getElementById('error-balance').innerHTML = "<FONT COLOR='#FF0000'>*</FONT>";
            balance.style.borderStyle = "solid";
            balance.style.borderColor = "#FF0000";
            balance.style.borderWidth = "1px";
            balance.focus();
            return false;
          }else{
            balance.style.borderStyle = "solid";
            balance.style.borderColor = "#00CC00";
            balance.style.borderWidth = "1px";
            document.getElementById('error-balance').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
          }
           
          //Check interest
          var interest = document.getElementById("interest");
          if (trimString(interest.value) == '') {
            alert("กรุณากรอกดอกเบี้ย");
            document.getElementById('error-interest').innerHTML = "<FONT COLOR='#FF0000'>*</FONT>";
            interest.style.borderStyle = "solid";
            interest.style.borderColor = "#FF0000";
            interest.style.borderWidth = "1px";
            interest.focus();
            return false;
          }else{
            interest.style.borderStyle = "solid";
            interest.style.borderColor = "#00CC00";
            interest.style.borderWidth = "1px";
            document.getElementById('error-interest').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
          }
        }

        function addFinance(){
          //alert("up");
          var url = 'index.php?module=InnoForum&type=moderateajax&func=validateFinnance&uid=' + <!--[$user.uid]--> + '&topic_id=' + <!--[$extendResult.topics.id]-->;
          //alert(url);
          new Ajax.Request(url, {
            method:'get',
            onSuccess: function(transport){
                var result = transport.responseText;
                if(trimString(result) == ''){
                  alert("กรุณาเข้าสู่ระบบ")
                }else{
                  
                  if(trimString(result) == "true"){

                    document.getElementById('company_name').disabled=false;
                    document.getElementById('balance').disabled=false;
                    document.getElementById('interest').disabled=false;
                    document.getElementById('finance_telephone').disabled=false;
                    document.getElementById('finance_email').disabled=false;
                    document.getElementById('max_installment').disabled=false;
                    document.getElementById('min_installment').disabled=false;
                    document.getElementById('btnSubmit').disabled=false;
                    document.getElementById('btnValidate').disabled=true;
                    document.getElementById('vat').innerHTML = '<INPUT TYPE="radio" NAME="form[vat]" value="1" checked>&nbsp;มี &nbsp;<INPUT  TYPE="radio" NAME="form[vat]" value="2" >&nbsp;ไม่มี</span>';
                    //alert(""+ result +" : validate");
                  }else{

                    document.getElementById('finance_id').value = '';
                    document.getElementById('company_name').value = '';
                    document.getElementById('balance').value = '';
                    document.getElementById('interest').value = '';
                    document.getElementById('max_installment').value = '12';
                    document.getElementById('min_installment').value = '12';

                    document.getElementById('company_name').disabled=true;
                    document.getElementById('balance').disabled=true;
                    document.getElementById('interest').disabled=true;
                    document.getElementById('finance_telephone').disabled=true;
                    document.getElementById('finance_email').disabled=true;
                    document.getElementById('max_installment').disabled=true;
                    document.getElementById('min_installment').disabled=true;
                    document.getElementById('vat').disabled=true;
                    alert("คุณได้จัดไฟแนนซ์ในประกาศนี้แล้ว");

                    //alert(""+ result +" : not validate");
                  }
                }
              }
          });
        }

        function computeFinance(balance, interest, installment, vat, installmentElement, payElement, computeAllElement, hiddenEstimatePriceElement){

          balanceFloat = parseFloat(document.getElementById(hiddenEstimatePriceElement).value);
          interestFloat = parseFloat(interest);
          vatFloat = parseFloat(vat);
          installmentInt = parseInt(installment);


          var allFinanceProfit = parseFloat(balanceFloat*(interestFloat/100)*installmentInt);
          var financeProfitPerMonth = parseFloat(allFinanceProfit/installmentInt);
          var totalPayment = Math.round(parseFloat(balanceFloat+allFinanceProfit));
          var payPerMonth = Math.round(parseFloat(totalPayment/installmentInt));

          if(vat == 7){
            var totalPayment = Math.round(parseFloat(totalPayment*1.07));
            var payPerMonth = Math.round(parseFloat(payPerMonth*1.07));
          }

          var nf = new NumberFormat(8563.04578);
          nf.setPlaces(3);
          nf.setSeparators(false);
          var num = nf.toFormatted();

          var displayFormatPayPerMonth = addCommas(payPerMonth);
          var displayFormatTotalPayment = addCommas(totalPayment);

          /* Debug script
          var totalPaymentIncludeVat =  Math.round(parseFloat(totalPayment*1.07));
          var payPerMonthIncludeVat =  Math.round(parseFloat(payPerMonth*1.07));
          var displayFormatPayPerMonthIncludeVat =  new NumberFormat(payPerMonthIncludeVat).toFormatted();
          var displayFormatTotalPaymentIncludeVat =  new NumberFormat(totalPaymentIncludeVat).toFormatted();
          alert("balance:"+balanceFloat);
          alert("interest:"+interestFloat);
          alert("installment:"+installmentInt);
          alert("vat:"+vatFloat);
          alert("Finance profit:"+allFinanceProfit);
          alert("Finance profit/month:"+financeProfitPerMonth);
          alert("Pay/month:"+payPerMonth);
          alert("total payment:"+totalPayment);
          alert("Pay/month(vat):"+payPerMonthIncludeVat);
          alert("total payment(vat):"+totalPaymentIncludeVat);
          */

          document.getElementById(installmentElement).innerHTML="<IMG SRC='modules/InnoForum/pnimages/ajax-loader-2.gif' WIDTH='16' HEIGHT='16'>";
          document.getElementById(installmentElement).innerHTML=installment;
          document.getElementById(payElement).innerHTML="<IMG SRC='modules/InnoForum/pnimages/ajax-loader-2.gif' WIDTH='16' HEIGHT='16'>";
          document.getElementById(payElement).innerHTML="<FONT COLOR='#FF0000'><B>"+displayFormatPayPerMonth+"</B></FONT>";
          document.getElementById(computeAllElement).innerHTML=displayFormatTotalPayment;
        }


        function addCommas(nStr){
          nStr += '';
          x = nStr.split('.');
          x1 = x[0];
          x2 = x.length > 1 ? '.' + x[1] : '';
          var rgx = /(\d+)(\d{3})/;
          while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
          }
          return x1 + x2;
        }

        function showElement(descElement, showButtonElement, hideButtonElement){
            document.getElementById(showButtonElement).style.display='none';
            document.getElementById(hideButtonElement).style.display='';
            document.getElementById(descElement).style.display='';
        }

        function hideElement(descElement, showButtonElement, hideButtonElement){
            document.getElementById(showButtonElement).style.display='';
            document.getElementById(hideButtonElement).style.display='none';
            document.getElementById(descElement).style.display='none';
        }

        function showEditPriceElement(userPriceElement, editPriceElement, submitPriceElement, price, hiddenEstimatePriceElement, id){
            var installment = document.getElementById("installment"+id).innerHTML;
            if(installment == "" || installment == "-"){
                alert("กรุณาเลือกจำนวนงวดก่อน");
                return false;
            }
            document.getElementById(editPriceElement).style.display='none';
            document.getElementById(submitPriceElement).style.display='';
            document.getElementById(userPriceElement).innerHTML='<input id="userEditPrice'+id+'" type="text" size="10" name="" value="'+price+'">';
        }

        function hideEditPriceElement(  userPriceElement, 
                                        editPriceElement, 
                                        submitPriceElement, 
                                        hiddenEstimatePriceElement, 
                                        id, 
                                        balance, 
                                        interest, 
                                        vat, 
                                        installmentElement, 
                                        payElement, 
                                        computeAllElement
                                      ){

          var editPriceOriginal = document.getElementById("userEditPrice"+id).value;
          var installment = document.getElementById("installment"+id).innerHTML;
          if(installment == "" || installment == "-"){
              alert("กรุณาเลือกจำนวนงวดก่อน");
              return false;
          }

          if(editPriceOriginal <= balance){
            var editPrice = addCommas(editPriceOriginal);
            document.getElementById(editPriceElement).style.display='';
            document.getElementById(submitPriceElement).style.display='none';
            document.getElementById(hiddenEstimatePriceElement).value=editPriceOriginal;
            document.getElementById(userPriceElement).innerHTML=editPrice;
            computeFinance(editPrice, interest, installment, vat, installmentElement, payElement, computeAllElement, hiddenEstimatePriceElement);
          }else{
            alert("ราคาที่กรอกเกินกว่าราคาที่ได้ประเมิณไว้")
          }
        }

  </script>
  <table width="99%" cellpadding="5px" cellspacing="0px" style="background-color:#FFFFFF; border:1px solid #CCCCCC; text-align:left;">
    <tr class="blue_header">
      <td>
        <h3 class="text_hblue">ยอดจัดไฟแนนซ์</h3>  
      </td>
    </tr>
    <tr>
      <td>
        <fieldset style="border:1px solid #eee">
        <!--[securityutil_checkpermission_block component='InnoForum::' instance='::' level=ACCESS_MODERATE]-->
          <FORM method="post" action="<!--[pnmodurl modname='InnoForum' type='moderateform' func='submit' ctrl='Finance']-->" onsubmit="return validateFinance()">
            <INPUT id="finance_id" TYPE="hidden" NAME="form[id]" value="">
            <INPUT TYPE="hidden" NAME="form[uid]" value="<!--[$user.uid]-->">
            <INPUT TYPE="hidden" NAME="form[topic_id]" value="<!--[$extendResult.topics.id]-->">
            <TABLE id="background-image">
              <TR>
                <TD align="right">จัดไฟแนนซ์ประกาศนี้ : </TD>
                <TD ><INPUT TYPE="button" VALUE="คลิกเพื่อจัดไฟแนนซ์" ONCLICK="addFinance();" id="btnValidate"></TD>
              </TR>
              <TR>
                <TD align="right">ชื่อบริษัท : </TD>
                <TD><INPUT TYPE="text" id="company_name" NAME="form[company_name]" value="" disabled><span id="error-company_name"></span></TD>
              </TR>
              <TR>
                <TD align="right">เบอร์โทรศัพท์ : </TD>
                <TD><INPUT TYPE="text" id="finance_telephone" NAME="form[finance_telephone]" value="" disabled><span id="error-finance_telephone"></span></TD>
              </TR>
              <TR>
                <TD align="right">อีเมล์ : </TD>
                <TD><INPUT TYPE="text" id="finance_email" NAME="form[finance_email]" value="" disabled><span id="error-finance_email"></span></TD>
              </TR>
              <TR>
                <TD align="right">ยอดจัด : </TD>
                <TD><INPUT TYPE="text" id="balance" NAME="form[balance]" value="" disabled> บาท &nbsp;<span id="error-balance"></span></TD>
              </TR>
              <TR>
                <TD align="right">อัตราดอกเบี้ย : </TD>
                <TD><INPUT TYPE="text" id="interest" NAME="form[interest]" value="" size="4" maxlength="5" disabled> ร้อยละต่อปี <span id="error-interest"></span></TD>
              </TR>
              <TR>
                <TD align="right">ระยะเวลาผ่อนชำระต่ำสุด : </TD>
                <TD>
                  <SELECT NAME="form[min_installment]" value="" id="min_installment" disabled>
                    <OPTION VALUE="12">12
                    <OPTION VALUE="24">24
                    <OPTION VALUE="36">36
                    <OPTION VALUE="48">48
                    <OPTION VALUE="60">60
                    <OPTION VALUE="72">72
                    <OPTION VALUE="84">84
                  </SELECT>
                </TD>
              </TR>
              <TR>
                <TD align="right">ระยะเวลาผ่อนชำระสูงสุด : </TD>
                <TD>
                  <SELECT NAME="form[max_installment]" value="" id="max_installment" disabled>
                    <OPTION VALUE="12">12
                    <OPTION VALUE="24">24
                    <OPTION VALUE="36">36
                    <OPTION VALUE="48">48
                    <OPTION VALUE="60">60
                    <OPTION VALUE="72">72
                    <OPTION VALUE="84">84
                  </SELECT>
                </TD>
              </TR>
              <TR>
                <TD align="right">ภาษี 7% : </TD>
                <TD><span id="vat"><INPUT TYPE="radio" NAME="form[vat]" value="1" checked disabled>&nbsp;มี &nbsp;<INPUT TYPE="radio" NAME="form[vat]" value="2" disabled>&nbsp;ไม่มี</span></TD>
              </TR>
              <TR>
                <TD align="center" colspan="2"><INPUT TYPE="submit" value="เสร็จสิ้น" id="btnSubmit" disabled></TD>
              </TR>
            </TABLE>
          </FORM>
        <BR>
        <hr>
        <!--[/securityutil_checkpermission_block]--><BR>

          <TABLE id="finance-list"><thead>
            <TR>
              <th width="20%">ชื่อบริษัท</th>
              <th width="18%">ผู้จัด</th>
              <th width="14%">ยอดจัด<br/>(บาท)</th>
              <th width="14%">งวดผ่อน<br/>(เดือน)</th>
              <th width="14%">ดอกเบี้ย<br/>(ร้อยละ/ปี)</th>
              <th width="4%">vat<br/>(7%)</th>
              <th width="16%">การผ่อนชำระ</th>
            </TR>
            <tbody>
            <!--[if $extendResult.finance]-->
              <!--[foreach from=$extendResult.finance item=item]-->
                <TR>                  
                  <TD>
                    <input id="company<!--[$item.id]-->" value="<!--[$item.company_name]-->"  type="hidden"><!--[$item.company_name]-->
                  </TD>
                  <TD>
                    <!--[getusername uid=$item.uid]-->
                  </TD>
                  <TD>
                    <input id="balance<!--[$item.id]-->" value="<!--[$item.balance]-->"  type="hidden"><!--[$item.balance|number_format:0]-->
                  </TD>
                  <TD>
                      <input id="max_installment<!--[$item.id]-->" value="<!--[$item.max_installment]-->"  type="hidden">
                      <input id="min_installment<!--[$item.id]-->" value="<!--[$item.min_installment]-->"  type="hidden">
                      <!--[if $item.max_installment == $item.min_installment]-->
                        <!--[$item.max_installment]--> - <!--[$item.max_installment]-->
                      <!--[else]-->
                        <!--[$item.min_installment]--> - <!--[$item.max_installment]-->
                      <!--[/if]-->
                  </TD>
                  <TD><input id="interest<!--[$item.id]-->" value="<!--[$item.interest]-->"  type="hidden"><!--[$item.interest]--></TD>
                  <TD><input id="vat<!--[$item.id]-->" value="<!--[$item.vat]-->"  type="hidden"><!--[if $item.vat == 1]--> มี <!--[else]-->ไม่มี<!--[/if]--></TD>
                  <TD rowspan="2">
                    <INPUT TYPE="button" 
                            id="showButton<!--[$item.id]-->" 
                            VALUE="คำนวนค่างวด" 
                            ONCLICK="showElement('desc<!--[$item.id]-->', 'showButton<!--[$item.id]-->', 'hideButton<!--[$item.id]-->');"
                    >
                    <INPUT TYPE="button" 
                            id="hideButton<!--[$item.id]-->" 
                            VALUE="ปิดการคำนวน" 
                            ONCLICK="hideElement('desc<!--[$item.id]-->', 'showButton<!--[$item.id]-->', 'hideButton<!--[$item.id]-->');" 
                            style="display:none"
                    >
                  <!--[if $user.uid eq $item.uid]-->
                    <script language="javascript">
                      function editFinance(idElement, companyElement, balanceElement, interestElement, finance_telephoneElement, finance_emailElement, minInstallmentElement, maxInstallmentElement, vatElement){

                        document.getElementById('finance_id').value = idElement;
                        document.getElementById('company_name').value = document.getElementById(companyElement).value;
                        document.getElementById('balance').value = document.getElementById(balanceElement).value;
                        document.getElementById('interest').value = document.getElementById(interestElement).value;
                        document.getElementById('finance_telephone').value= document.getElementById(finance_telephoneElement).value;
                        document.getElementById('finance_email').value= document.getElementById(finance_emailElement).value;
                        document.getElementById('max_installment').value = document.getElementById(maxInstallmentElement).value;
                        document.getElementById('min_installment').value = document.getElementById(minInstallmentElement).value;

                        document.getElementById('company_name').disabled=false;
                        document.getElementById('balance').disabled=false;
                        document.getElementById('interest').disabled=false;
                        document.getElementById('finance_telephone').disabled=false;
                        document.getElementById('finance_email').disabled=false;
                        document.getElementById('max_installment').disabled=false;
                        document.getElementById('min_installment').disabled=false;
                        document.getElementById('vat').disabled=false;

                        document.getElementById('btnSubmit').disabled=false;
                        document.getElementById('btnValidate').disabled=true;

                        var vat = document.getElementById(vatElement).value;

                        if(vat == '1'){
                          document.getElementById('vat').innerHTML = '<INPUT TYPE="radio" NAME="form[vat]" value="1" checked>&nbsp;มี &nbsp;<INPUT  TYPE="radio" NAME="form[vat]" value="2">&nbsp;ไม่มี</span>';
                        }else{
                          document.getElementById('vat').innerHTML = '<INPUT TYPE="radio" NAME="form[vat]" value="1" >&nbsp;มี &nbsp;<INPUT  TYPE="radio" NAME="form[vat]" value="2" checked>&nbsp;ไม่มี</span>';
                        }
                      }
                    </script>
                    <INPUT TYPE="button" 
                            VALUE="แก้ไข" 
                            ONCLICK="editFinance('<!--[$item.id]-->', 
                                                  'company<!--[$item.id]-->', 
                                                  'balance<!--[$item.id]-->', 
                                                  'interest<!--[$item.id]-->', 
                                                  'finance_telephone<!--[$item.id]-->', 
                                                  'finance_email<!--[$item.id]-->', 
                                                  'min_installment<!--[$item.id]-->', 
                                                  'max_installment<!--[$item.id]-->', 
                                                  'vat<!--[$item.id]-->'
                                                  );"
                    >
                  <!--[/if]-->
                  </TD>
                </TR>
                <TR>                  
                  <TD colspan="6">
                    เบอร์โทรศัพท์ : <input id="finance_telephone<!--[$item.id]-->" value="<!--[$item.finance_telephone]-->" type="hidden"><!--[$item.finance_telephone]-->&nbsp;&nbsp;|&nbsp;&nbsp;อีเมล์ : <input id="finance_email<!--[$item.id]-->" value="<!--[$item.finance_email]-->" type="hidden"><!--[$item.finance_email]-->
                  </TD>
                </TR>
                <TR id="desc<!--[$item.id]-->" style="display:none">
                  <TD colspan="7">
                    <TABLE id="finance-select">
                      <TR>
                        <TH width="90%" colspan="7">จำนวนงวด</TH>
                        <TH width="10%">vat 7%</TH>
                      </TR>
                      <TR>
                        <TD>12</TD>
                        <TD>24</TD>
                        <TD>36</TD>
                        <TD>48</TD>
                        <TD>60</TD>
                        <TD>72</TD>
                        <TD>84</TD>
                        <TD rowspan="2"><!--[if $item.vat == 1]-->มี<!--[else]-->ไม่มี<!--[/if]--></TD>
                      </TR>
                      <TR>
                        
                        <!--[if $item.max_installment == 12]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->',
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 24]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 36]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="36" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            36, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 48]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="36" 
                                    onclick="computeFinance(
                                                              <!--[$item.balance]-->, 
                                                              <!--[$item.interest]-->, 
                                                              36, 
                                                              <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                              'installment<!--[$item.id]-->', 
                                                              'pay<!--[$item.id]-->',
                                                              'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                              )"
                                                                                            >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="48" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            48, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 60]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="36" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            36, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="48" 
                                    onclick="computeFinance(
                                                              <!--[$item.balance]-->, 
                                                              <!--[$item.interest]-->, 
                                                              48, 
                                                              <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                              'installment<!--[$item.id]-->', 
                                                              'pay<!--[$item.id]-->',
                                                              'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                              )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="60" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            60, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 72]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="36" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            36, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="48" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            48, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="60" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            60, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="60" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            72, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>&nbsp;</TD>
                        <!--[elseif $item.max_installment == 84]-->
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="12" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            12, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="24" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            24, <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="36" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            36, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="48" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            48, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="60" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            60, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="72" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            72, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                          <TD>
                            <INPUT  TYPE="radio" 
                                    name="installment" 
                                    id="installment" 
                                    value="84" 
                                    onclick="computeFinance(
                                                            <!--[$item.balance]-->, 
                                                            <!--[$item.interest]-->, 
                                                            84, 
                                                            <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                            'installment<!--[$item.id]-->', 
                                                            'pay<!--[$item.id]-->',
                                                            'computeAll<!--[$item.id]-->',
                                                            'hiddenEstimatePrice<!--[$item.id]-->'
                                                            )"
                              >
                          </TD>
                        <!--[else]-->
                          -
                        <!--[/if]-->
                      </TR>
                    </TABLE>
                    <TABLE id="finance-sum">                    
                      <TR>
                        <TH colspan="4">รายละเอียดการผ่อน</TH>
                      </TR>
                      <TR>
                        <TD width="20%"><B>ยอดจัด :</B></TD>
                        <TD width="30%">
                          <FONT COLOR="#009900">
                            <B>
                              <INPUT TYPE="hidden" id="hiddenEstimatePrice<!--[$item.id]-->" NAME="hiddenEstimatePrice<!--[$item.id]-->" value="<!--[$item.balance]-->">
                              <INPUT TYPE="button" 
                                        id="editPrice<!--[$item.id]-->" 
                                        VALUE="แก้ไข" 
                                        ONCLICK="showEditPriceElement(
                                                                      'userPrice<!--[$item.id]-->', 
                                                                      'editPrice<!--[$item.id]-->', 
                                                                      'submitPrice<!--[$item.id]-->',
                                                                      <!--[$item.balance]-->, 
                                                                      'hiddenEstimatePrice<!--[$item.id]-->', 
                                                                      <!--[$item.id]-->
                                                                      );"
                                        >
                          &nbsp;<INPUT TYPE="button" 
                                        id="submitPrice<!--[$item.id]-->" 
                                        VALUE="ตกลง" 
                                        ONCLICK="hideEditPriceElement('userPrice<!--[$item.id]-->', 
                                                                      'editPrice<!--[$item.id]-->', 
                                                                      'submitPrice<!--[$item.id]-->', 
                                                                      'hiddenEstimatePrice<!--[$item.id]-->', 
                                                                      <!--[$item.id]-->,
                                                                      <!--[$item.balance]-->, 
                                                                      <!--[$item.interest]-->, 
                                                                      <!--[if $item.vat == 1]-->7<!--[else]-->0<!--[/if]-->, 
                                                                      'installment<!--[$item.id]-->',
                                                                      'pay<!--[$item.id]-->',
                                                                      'computeAll<!--[$item.id]-->'
                                                                     );" 
                                        style="display:none"
                                        ><span id="userPrice<!--[$item.id]-->"><!--[$item.balance|number_format:0]--></span>
                            </B>
                          </FONT>&nbsp;บาท
                        </TD>
                        <TD width="20%"><B>งวดผ่อน :</B> </TD>
                        <TD width="30%"><span id="installment<!--[$item.id]-->">-</span>&nbsp;งวด</TD>
                      </TR>
                      <TR>
                        <TD><B>อัตราดอกเบี้ย :</B></TD>
                        <TD>ร้อยละ <!--[$item.interest]--> ต่อปี</TD>
                        <TD><B>ยอดผ่อนต่อเดือน :</B></TD>
                        <TD><span id="pay<!--[$item.id]-->">-</span>&nbsp;บาท</TD>
                      </TR>
                      <TR>
                        <TD>&nbsp;</TD>
                        <TD>&nbsp;</TD>
                        <TD><B>รวมทั้งหมด :</B></TD>
                        <TD><span id="computeAll<!--[$item.id]-->">-</span>&nbsp;บาท</TD>
                      </TR>
                    </TABLE>
                  </TD>
                </TR>
              <!--[/foreach]-->
            <!--[else]-->
                <TR>
                  <TH colspan="7"><FONT COLOR="#FF0000">ยังไม่มีข้อมูล</FONT></TH>
                </TR>
            <!--[/if]-->
            </tbody>
          </TABLE>
        </fieldset>
      </td>
    </tr>
  </table>